using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SpoonCore2.Message;
using SpoonCore2.Client;

namespace SpoonCore2.Service.Broadcast
{
	class BroadcastMessage : AbstractMessage
	{
		private SpoonIdentifier _broadcastGroup = new SpoonIdentifier();
		private byte[] _data;

		public byte[] Data
		{
			get { return _data; }
			set { _data = value; }
		}

		public SpoonIdentifier BroadcastGroup
		{
			get { return _broadcastGroup; }
			set { _broadcastGroup = value; }
		}

		public override void GetBytes(BinaryWriter bw)
		{
			bw.Write(_broadcastGroup.GetBytes());
			if (_data != null)
			{
				bw.Write(_data.Length);
				bw.Write(_data);
			}
		}

		public override void SetBytes(IService service, BinaryReader br)
		{
			_broadcastGroup = new SpoonIdentifier(br);
			int count;
			if((count= br.ReadInt32()) > 0) _data = br.ReadBytes(count);
		}
	}
}